package com.justgame.project.service.system.service.basic;

import com.justgame.project.service.system.entity.SysUserAccount;
import com.justgame.project.service.system.query.SysUserAccountQuery;
import com.justgame.project.service.system.wrapper.SysUserAccountWrapper;
import com.justgame.project.base.servcice.IBasicService;
import java.util.Optional;
import org.springframework.util.Assert;
import java.lang.Long;
import org.springframework.lang.NonNull;
import java.math.BigDecimal;

/**
 *
 * 用户账户信息表服务自定义查询类
 *
 * @@tableName sys_user_account
 * @author Zwb
 */
@SuppressWarnings("all")
public interface BasicSysUserAccountService extends IBasicService<SysUserAccountQuery,SysUserAccount,SysUserAccountWrapper> {

   /**
    * 用户注册后调用创建用户账户信息
    * @param userInfoId 用户信息
    * @param coin 硬币
    * @param integral 积分
    * @param rmb 账户人民币余额
    */
   default SysUserAccount addByUserRegister(Long userInfoId, BigDecimal coin, BigDecimal integral){
      Assert.notNull(userInfoId,"必须提供用户信息");
      SysUserAccount sysUserAccount = new SysUserAccount();
      sysUserAccount.setUserInfoId(safeValue(userInfoId, null));
      sysUserAccount.setCoin(safeValue(coin, BigDecimal.ZERO));
      sysUserAccount.setIntegral(safeValue(integral, BigDecimal.ZERO));
      sysUserAccount.setRmb(BigDecimal.ZERO);
      save(sysUserAccount);
      return sysUserAccount;
   }

   /**
    * 查询通过字段：用户信息
    * @param userInfoIdIs 用户信息
    */
   default Optional<SysUserAccount> findByUserInfoIdIs(Long userInfoIdIs){
      Assert.notNull(userInfoIdIs,"必须提供用户信息");
      return Optional.ofNullable(getOne(SysUserAccountQuery.builder().getWrapper()
                  .eq(SysUserAccount::getUserInfoId,userInfoIdIs)));
   }

   /**
    * 新增创建
    * @param userInfoId 用户信息
    * @param coin 硬币
    * @param integral 积分
    * @param rmb 账户人民币余额
    */
   default SysUserAccount baseAdd(Long userInfoId, BigDecimal coin, BigDecimal integral, BigDecimal rmb){
      SysUserAccount sysUserAccount = new SysUserAccount();
      sysUserAccount.setUserInfoId(safeValue(userInfoId, null));
      sysUserAccount.setCoin(safeValue(coin, null));
      sysUserAccount.setIntegral(safeValue(integral, null));
      sysUserAccount.setRmb(safeValue(rmb, null));
      save(sysUserAccount);
      return sysUserAccount;
   }

   /**
    * 更新
    * @param userInfoId 用户信息
    * @param coin 硬币
    * @param integral 积分
    * @param rmb 账户人民币余额
    */
   default boolean baseUpdate(@NonNull SysUserAccount sysUserAccount,Long userInfoId, BigDecimal coin, BigDecimal integral, BigDecimal rmb){
      Assert.notNull(userInfoId,"必须提供用户信息");
      Assert.notNull(coin,"必须提供硬币");
      Assert.notNull(rmb,"必须提供账户人民币余额");
      Assert.notNull(integral,"必须提供积分");
      Assert.notNull(sysUserAccount.getId(),"必须提供主键ID");
      sysUserAccount.setUserInfoId(safeValue(userInfoId, null));
      sysUserAccount.setCoin(safeValue(coin, null));
      sysUserAccount.setIntegral(safeValue(integral, null));
      sysUserAccount.setRmb(safeValue(rmb, null));
      return updateById(sysUserAccount);
   }

}